package com.dt.platform.generator.module.hr;


import com.dt.platform.constants.db.HrTables;
import com.dt.platform.constants.enums.common.StatusEnableEnum;
import com.dt.platform.constants.enums.common.YesNoEnum;
import com.dt.platform.constants.enums.hr.LearnTypeEnum;
import com.dt.platform.domain.hr.Learn;
import com.dt.platform.domain.hr.PaperQuestion;
import com.dt.platform.domain.hr.TrainingInstructor;
import com.dt.platform.domain.hr.meta.LearnMeta;
import com.dt.platform.domain.hr.meta.PaperMeta;
import com.dt.platform.domain.hr.meta.TrainingInstructorMeta;
import com.dt.platform.generator.config.Config;
import com.dt.platform.hr.page.LearnPageController;
import com.dt.platform.proxy.hr.LearnServiceProxy;
import com.dt.platform.proxy.hr.TrainingInstructorServiceProxy;
import com.github.foxnic.generator.builder.view.config.DatePickerType;
import com.github.foxnic.generator.config.WriteMode;
import org.github.foxnic.web.domain.hrm.Employee;


public class ALeanGtr extends BaseCodeGenerator {
    public ALeanGtr() {
        super(HrTables.HR_LEARN.$TABLE,"811268060357853184");
    }

    public void generateCode() throws Exception {
        System.out.println(this.getClass().getName());


        cfg.getPoClassFile().addSimpleProperty(TrainingInstructor.class,"trainingInstructor","trainingInstructor","trainingInstructor");


        cfg.view().field(HrTables.HR_LEARN.ID).basic().hidden(true);
        cfg.view().field(HrTables.HR_LEARN.NAME).search().fuzzySearch();

        cfg.view().field(HrTables.HR_LEARN.NAME).form().validate().required();
        cfg.view().field(HrTables.HR_LEARN.SDATE).form().validate().required().form().dateInput().type(DatePickerType.datetime).format("yyyy-MM-dd HH:mm:ss").defaultNow().search().range();
        cfg.view().field(HrTables.HR_LEARN.EDATE).form().validate().required().form().dateInput().type(DatePickerType.datetime).format("yyyy-MM-dd HH:mm:ss").defaultNow().search().range();
        cfg.view().field(HrTables.HR_LEARN.CREATE_TIME).search().range();

        cfg.view().field(HrTables.HR_LEARN.COST).form().validate().required().form().numberInput().decimal().scale(1).defaultValue(45.0);


        cfg.view().search().inputLayout(
                new Object[]{
                        HrTables.HR_LEARN.TYPE,
                        HrTables.HR_LEARN.LECTURER_ID,
                        HrTables.HR_LEARN.NAME,
                },
                new Object[]{
                        HrTables.HR_LEARN.CREATE_TIME,
                }
        );

        cfg.view().list().disableBatchDelete();

        cfg.view().field(HrTables.HR_LEARN.UPDATE_BY).form().table().disable(true);
        cfg.view().field(HrTables.HR_LEARN.UPDATE_BY).form().table().disable(true);
        cfg.view().field(HrTables.HR_LEARN.UPDATE_TIME).form().table().disable(true);
        cfg.view().field(HrTables.HR_LEARN.STATUS).form().table().disable(true);

        cfg.view().field(HrTables.HR_LEARN.FILE_IDS).form().table().disable(true);
        cfg.view().field(HrTables.HR_LEARN.FILE_ID).form().table().disable(true);
        cfg.view().field(HrTables.HR_LEARN.VIDEO_ID).form().table().disable(true);


        cfg.view().field(HrTables.HR_LEARN.STATUS).basic().label("启用状态").form()
              .radioBox().enumType(StatusEnableEnum.class).defaultIndex(0);

        cfg.view().field(HrTables.HR_LEARN.IF_REPEAT).form().validate().required().form()
                .radioBox().enumType(YesNoEnum.class).defaultIndex(0);

        cfg.view().field(HrTables.HR_LEARN.TYPE).form().validate().required().form()
                .radioBox().enumType(LearnTypeEnum.class).defaultIndex(0);

        cfg.view().field(HrTables.HR_LEARN.FILE_IDS).form().upload().maxFileCount(3).acceptAllType();
        cfg.view().field(HrTables.HR_LEARN.FILE_ID).form().upload().maxFileCount(1).acceptAllType();
        cfg.view().field(HrTables.HR_LEARN.VIDEO_ID).form().upload().maxFileCount(1).acceptVideoType();


        cfg.view().field(HrTables.HR_LEARN.LECTURER_ID).form().validate().required().form().selectBox()
                .queryApi(TrainingInstructorServiceProxy.QUERY_PAGED_LIST)
                .paging(true).filter(true).toolbar(false)
                .valueField(TrainingInstructorMeta.ID).
                textField(TrainingInstructorMeta.NAME).
                fillWith(LearnMeta.TRAINING_INSTRUCTOR).muliti(false);



        cfg.view().search().labelWidth(1,Config.searchLabelWidth);
        cfg.view().search().labelWidth(2,Config.searchLabelWidth);
        cfg.view().search().labelWidth(3,Config.searchLabelWidth);
        cfg.view().search().labelWidth(4,Config.searchLabelWidth);
        cfg.view().search().inputWidth(Config.searchInputWidth);


        cfg.view().search().rowsDisplay(1);
        cfg.view().formWindow().width("80%");;
        cfg.view().formWindow().bottomSpace(150);

        cfg.view().form().addGroup(null,
                new Object[] {
                        HrTables.HR_LEARN.NAME,
                        HrTables.HR_LEARN.IF_REPEAT,
                        HrTables.HR_LEARN.LECTURER_ID,
                        HrTables.HR_LEARN.COST,
                },
                new Object[] {
                        HrTables.HR_LEARN.TYPE,
                        HrTables.HR_LEARN.SDATE,
                        HrTables.HR_LEARN.EDATE,
                }
        );


        cfg.view().form().addGroup(null,
                new Object[] {
                        HrTables.HR_LEARN.FILE_IDS
                }
        );

        cfg.view().form().addGroup("课程内容",
                new Object[] {
                        HrTables.HR_LEARN.VIDEO_ID,
                },
                new Object[] {
                        HrTables.HR_LEARN.FILE_ID,
                }
        );


        cfg.view().list().operationColumn().addActionButton("任务","release","release");
        cfg.view().list().operationColumn().addActionButton("预览","review","review");

        //文件生成覆盖模式
        cfg.overrides()
                .setServiceIntfAnfImpl(WriteMode.IGNORE) //服务与接口
                .setControllerAndAgent(WriteMode.IGNORE) //Rest
                .setPageController(WriteMode.IGNORE) //页面控制器
                .setBpmEventAdaptor(WriteMode.COVER_EXISTS_FILE)
                .setFormPage(WriteMode.COVER_EXISTS_FILE) //表单HTML页
                .setListPage(WriteMode.COVER_EXISTS_FILE) //列表HTML页
                .setExtendJsFile(WriteMode.IGNORE);
        //生成代码
        cfg.buildAll();
    }

    public static void main(String[] args) throws Exception {
        ALeanGtr g=new ALeanGtr();
        //生成代码
        g.generateCode();

        //移除之前生成的菜单，视情况执行
       // System.out.println("############"+g.getTablePrefix());
       // g.removeByBatchId("801716675761143808");
      //  //生成菜单
      // g.generateMenu(LearnServiceProxy.class, LearnPageController.class);
    }
}
